﻿package {
	import flash.display.*;
	import flash.geom.*;
	
	public class Region {
		
		private var items:Array = null;
		private var rectangle = new Sprite();
//		private var mole = new Mole();
		
		public function Region() {
			init();	
		}
		
		public function init() {
			items = new Array();
//			showMole(true);
		}
		
		public function getItems(){
			return items;
		}
		
		public function countItems(){
			return items.length;
		}
		
		public function getCentre() 
		{
			var coord:Object = {"x": rectangle.x + (rectangle.width / 2), "y": rectangle.y  + (rectangle.height / 2)};

			return coord;
		}

		public function getGlobalCentre() 
		{
			var pt1:Point = new Point(rectangle.x, rectangle.y);
			pt1 = rectangle.localToGlobal(pt1);
			
			var coord:Object = {"x": pt1.x + (rectangle.width / 2), "y": pt1.y  + (rectangle.height / 2)};

			return coord;
		}
		
		public function addItem(newItem){
			items.push(newItem);
			//rectangle.addChild(newItem);
		}
		
		public function removeItem(outItem){
			var maxItems = items.length;
			var changedItems:Array = new Array();
			for(var itemNo = 0; itemNo < maxItems; itemNo++){
				if (items[itemNo] != outItem) {
					changedItems.push(items[itemNo]);
				}
			}
			items = changedItems;
		}
		
		public function getRectangle()
		{
			return rectangle;
		}
		
		public function setRectangle(x:int, y:int, width:int, height:int)
		{
//			trace("setRectangle x: "+x+" y: "+x+" w: "+width+" h: "+height);//TMP

			rectangle.graphics.lineStyle(2, 0xCCCCCC, 0);
//			rectangle.graphics.drawRect(x, y, width, height);
			rectangle.graphics.drawRect(0, 0, width, height);
			rectangle.graphics.endFill();
			rectangle.x = x;
			rectangle.y = y;
//			mole.x = width/2;
//			mole.y = height/2;
		}
/*		
		public function showMole(show:Boolean){
			if(show){
				rectangle.addChild(mole);
			}else{
				rectangle.removeChild(mole);
			}
		}
*/		
	}
}